package com.tz.farmer.util;


import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.GetClient;
import com.tz.farmer.config.ExecutableClientConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ZzdUtil {
    private static Logger logger = LoggerFactory.getLogger(ZzdUtil.class);


    public static String getAccessToken() {
        Map<String,String> map=new HashMap<>();
        try {
//            map.put("appkey","tyl_login_dingoa-8Vs5q2kvayqqy");
//            map.put("appsecret","113vj5G6El4W7917g2f659MzFSog9XyU8ZCpJcw4");
            map.put("appkey","tzscjg_tyl_dingoa-7GGwwja2YvMv");
            map.put("appsecret","F39FJwe5k77T7253O8w2u696xleRS1s3zPOdvW9M");
            String apiResult=ExecutableClientConfig.doGet("/gettoken.json",map);
            logger.info("生成token接口返回" + apiResult);
            JSONObject jsonObj = JSONObject.parseObject(apiResult);
            String content = jsonObj.get("content") + "";
            String data = JSONObject.parseObject(content).get("data") + "";
            String accessToken = JSONObject.parseObject(data).get("accessToken") + "";
            return accessToken;
        }catch (Exception e){
            logger.error(e.getMessage());
            return  null;
        }
    }
}
